/**
 * 62. 不同路径
 * https://leetcode-cn.com/problems/unique-paths/
 */

/**
 * @param {number} m
 * @param {number} n
 * @return {number}
 */
function uniquePaths(m, n) {
  if (m > n) {
    const temp = m;
    m = n;
    n = temp;
  }
  const line = new Array(n).fill(1);
  for (let i = 1; i < m; i += 1) {
    for (let j = 1; j < n; j += 1) {
      line[j] += line[j - 1];
    }
  }
  return line[n - 1];
}

console.log(uniquePaths(3, 7) === 28);
console.log(uniquePaths(3, 2) === 3);
console.log(uniquePaths(7, 3) === 28);
console.log(uniquePaths(3, 3) === 6);
